package vip.hello520.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomResolverException implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
		HttpServletResponse response, Object handler, Exception ex) {

		CustomException ec;
		if (ex instanceof CustomException) {
			ec = (CustomException) ex;
		} else {
			ec = new CustomException("未知错误");
		}
		String msg = ec.getMessage();
		ModelAndView mav = new ModelAndView();
		mav.addObject("msg_error", msg);
		mav.setViewName("error");
		return mav;
	}
}
